package com.demo.common.support.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * 返回对象公共实体
 *
 * @author molong
 * @since 2024/5/24
 */
public abstract class BaseResponse<T> implements DataResponse<T> {

    private final long responseTime = System.currentTimeMillis();

    /**
     * 扩展数据,对额外的数据都通过此字段进行返回
     */
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    @JsonProperty("_extend")
    private Map<String, Object> extend;

    private String message = "success";

    private int code = 0;

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public int getCode() {
        return code;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        Assert.notNull(extend, "data cannot be null");
        this.extend = extend;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public long getResponseTime() {
        return responseTime;
    }

    @Override
    public boolean isCollect() {
        return false;
    }
}
